package com.zh.book_borrow.Exception;


import com.zh.book_borrow.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
@ResponseBody
public class GlobalExceptionHandler {

    @ExceptionHandler(MyException.class)
    public Result<?> customError(MyException e) {
        log.error("异常信息：", e);
        return Result.error(e.getCode() + e.getMsg());
    }


    @ExceptionHandler(Exception.class)
    public Result error(Exception e) {
        log.error("异常信息：", e);
        return Result.error("系统异常");
    }

}
